package test;

public class 唤醒阻塞线程 {
    public static class Main {
        public static void main(String[] args) {
            // 创建一个线程，让它处于阻塞状态
            Thread thread1 = new Thread(() -> {
                synchronized (Main.class) {
                    try {
                        Main.class.wait();
                        System.out.println("Thread 1 has been awakened.");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            });

            // 创建一个线程，让它在 10 秒钟后唤醒另一个线程
            Thread thread2 = new Thread(() -> {
                try {
                    Thread.sleep(10000);
                    synchronized (Main.class) {
                        Main.class.notify();
                    }
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });

            // 启动线程
            thread1.start();
            thread2.start();
        }
    }
}
